package com.tz.farmer.controller;


import com.smartPark.msframe.result.ResultEx;
import com.tz.farmer.service.DataStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @description: 数据统计
 * @name BusinessController
 * @author: xhj
 * @date: 2021/6/23
 * @version V1.0
 */
@RestController
@RequestMapping("statistics")
@Api(value = "数据统计", tags = "数据统计控制器")
public class DataStatisticsController {


    private static Logger logger = LoggerFactory.getLogger(DataStatisticsController.class);

    @Resource
    DataStatisticsService dataStatisticsService;


    /**
     * @description:  数据统计
     * @name businessInfo
     * @author: xhj
     * @date: 2021/8/6 11:35
     * @version V1.0
     */
    @ApiOperation("查询数据统计(页面上方8个数据统计)")
    @GetMapping("statisticsInfo")
    public ResultEx getStatisticsInfo() {
        try {
            return dataStatisticsService.getStatisticsInfo();
        }catch (Exception e){
            logger.error("数据统计信息获取失败",e);
            return ResultEx.builder().makeFailedResult("数据统计信息获取失败");

        }
    }


    /**
     * @description:  主体上链总数
     * @name businessInfo
     * @author: xhj
     * @date: 2021/8/6 11:35
     * @version V1.0
     */
    @ApiOperation("查询主体上链总数")
    @GetMapping("mainTotal")
    public ResultEx getMainTotal() {
        try {
            return dataStatisticsService.getMainTotal();
        }catch (Exception e){
            logger.error("主体上链总数信息获取失败",e);
            return ResultEx.builder().makeFailedResult("主体上链总数信息获取失败");

        }
    }

    /**
     * @description:  台农/渔链上链趋势
     * @name businessInfo
     * @author: xhj
     * @date: 2021/8/6 11:35
     * @version V1.0
     */
    @ApiOperation("台农链上链趋势")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city", value = "区县名称", defaultValue = "",required = false),
            @ApiImplicitParam(name = "sign", value = "标记（台农链传331002 ,台渔链传331001）", defaultValue = "",required = true),
    })
    @GetMapping("farmerTrend")
    public ResultEx getFarmerTrend(String city,String sign) {
        try {
            return dataStatisticsService.getFarmerTrend(city,sign);
        }catch (Exception e){
            logger.error("台农链上链趋势信息获取失败",e);
            return ResultEx.builder().makeFailedResult("台农链上链趋势信息获取失败");

        }
    }

}
